<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>精灵跟随鼠标移动</title>
    <style>

      body{
          background-color: black;
      }
      img{
          position: absolute;
          top:0;
          left: 0;
      }
    </style>
</head>
<body>
<img src="img/girl.gif" id="img">
<script type="text/javascript">
    var  img=document.getElementById("img");
    //获取鼠标的位置
    window.onmousemove=function(event){
          console.log("鼠标移动了");
        var ev=event||window.event;
        img.style.top=(ev.pageY-100)+"px";
        img.style.left=(ev.pageX-100)+"px";
    }
</script>
</body>
</html>
